package br.com.puertorico.mecanismos.ui.functions;

import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang.StringUtils;

import br.com.puertorico.common.utils.DateFacility;
import br.com.puertorico.mecanismos.ui.utils.MessagesUtils;

public class FacesFunctions {
	public static String resolveAge(final Date date) {
		return resolveAge(date, new Date());
	}

	public static String resolveAge(final Date date, final Date now) {
		if (date == null) {
			return "";
		}
		Integer idade = DateFacility.getDateDiff(Calendar.YEAR, date, now);
		return idade.toString();
	}

	public static <T extends Enum<?>> String resolveEnum(final T enumValue) {
		return MessagesUtils.resolveEnum(enumValue);
	}

	public static String padZeroLeft(final String valor, final Integer size) {
		if (valor == null) {
			return null;
		}
		return StringUtils.leftPad(valor, size, "0");
	}
}
